﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using libnbot;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;

namespace nbot
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Config appConfig = null;
            String confFile = ".\\nbot.conf";
            if (!File.Exists(confFile))
            {
                appConfig = new Config();
                FileStream fstream = new FileStream(confFile, FileMode.OpenOrCreate, FileAccess.Write);
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(fstream, appConfig);
                fstream.Close();
            }
            else
            {
                FileStream fstream = new FileStream(confFile, FileMode.Open, FileAccess.Read);
                BinaryFormatter formatter = new BinaryFormatter();
                appConfig = (Config) formatter.Deserialize(fstream);
                fstream.Close();
            }

            if((null != appConfig) && (File.Exists(appConfig.DataEnginePlugIn)))
            {
                Assembly plugin = Assembly.LoadFile(Application.StartupPath + "\\" + appConfig.DataEnginePlugIn);
                Type dataEngineType = plugin.GetType(appConfig.DataEngineClass);
                IDataEngine dataEngine = (IDataEngine)Activator.CreateInstance(dataEngineType);
            }
        }
    }
}
